//
//  GSSearch_Cell.m
//  GameSky
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSSearch_Cell.h"

@implementation GSSearch_Cell
#pragma mark-----------------自定义初始化-----------------
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
//        cell 高度
        CGFloat height = kScreenHeight / 8;
        
// 图片
        self.pictureImageV = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, kScreenWidth / 4, height - 16)];
        [self.contentView addSubview:self.pictureImageV];
        
// 标题
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.titleLabel];

// 评论
        self.commentsCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(_pictureImageV.right + 8, 8 + height / 2, kScreenWidth - _pictureImageV.right - 8 - 8 - 29 - 16, height / 2 - 8  - 8)];
        _commentsCountLabel.textAlignment = NSTextAlignmentRight;
        _commentsCountLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.commentsCountLabel];
// 标签 图片
        self.badgesImageV = [[UIImageView alloc] initWithFrame:CGRectMake(_commentsCountLabel.right + 8, _commentsCountLabel.top, 29, _commentsCountLabel.height)];
        _badgesImageV.backgroundColor = [UIColor purpleColor];
        [self.contentView addSubview:self.badgesImageV];
    }
    return self;
}
#pragma mark-----------------重写setter方法----------------
- (void)setModel:(GSSearch_Model *)model{
    //        cell 高度
    CGFloat height = kScreenHeight / 8;
    _model = model;
// 各个控件赋值
    if (model.thumbnailURLs.count == 1) {
        // 显示图片
        _pictureImageV.alpha = 1;
        [_pictureImageV sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLs[0]] placeholderImage:nil];
        // 标题label frame
        _titleLabel.frame = CGRectMake(_pictureImageV.right + 8, 8, kScreenWidth - 8 - _pictureImageV.right - 8, height / 2);
        
    }else{
        _pictureImageV.alpha = 0;
    // 标题label  frame
        _titleLabel.frame = CGRectMake(8, 8, kScreenWidth - 16, height / 2);
    }
    _titleLabel.text = model.title;
// 评论
    if(model.badges == nil || model.badges.count == 0){
        // 如果没有 标签 ,则 改变 评论 frame
        _badgesImageV.alpha = 0;
        CGRect temp = _commentsCountLabel.frame;
        temp.size.width = kScreenWidth - _pictureImageV.right - 8 - 8;
        _commentsCountLabel.frame = temp;
    }else{
        _badgesImageV.alpha = 0;
        
    }
    _commentsCountLabel.text = [NSString stringWithFormat:@"%@评论",model.commentsCount];
}
#pragma mark---------------------------------------------

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
